<?php

namespace app\index\controller;

use think\exception\ValidateException;
use app\model\OrderStatus;

class OrderstatusController extends Base
{
    public function list()
    {
        $OrderStatus = OrderStatus::where('status', 1)
            ->order('id asc')
            ->select()
            ->toArray();
        foreach ($OrderStatus as $vo) {
            $data[$vo['id']] = $vo['name'];
        }

        return $this->json(['data' => $data]);
    }

    public function listname()
    {

        $OrderStatus = OrderStatus::where('status', 1)
            ->order('id asc')
            ->select()
            ->toArray();

        $ptype = input('get.ptype');

        if ($ptype == 2) {
            foreach ($OrderStatus as &$vo) {
                $vo['name'] = $vo['name_yuyue'];
            }
        }

        $data[0]['id'] = 0;
        $data[0]['weid'] = 0;
        $data[0]['name'] = '全部';
        $data[0]['status'] = 1;

        $data = array_merge($data, $OrderStatus);

        return $this->json(['data' => $data]);
    }

    public function settings()
    {
        $OrderStatus = OrderStatus::field('id,name')
            ->where('status', 1)
            ->order('id asc')
            ->select()
            ->toArray();

        $data = $OrderStatus;
        return $this->json(['data' => $data]);
    }
}
